package platform.nettyclient.handle;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.nio.charset.Charset;
import java.util.List;


/**
 * 自定义解码器
 */
public class Docer extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        byte[] bytes = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(bytes);
        String str = new String(bytes, Charset.forName("GBK"));
        System.out.println(str + "转码数据");
        // 存储后在MyClientHandler中msg中直接就是转码后的数据
        list.add(str);
    }
}
